package com.example.administrator.ttphonehelper.process;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.ttphonehelper.R;
import com.example.administrator.ttphonehelper.bean.ProcessBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/14 0014.
 */
public class ProcessAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private List<ProcessBean> mProcessList;

    public ProcessAdapter(List<ProcessBean> processes){
        mProcessList = new ArrayList<>();
        mProcessList = processes;


    }
    //设置ViewHolder关联的布局
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.process_item,parent,false);
        ItemViewHolder holder = new ItemViewHolder(view);

        return holder ;
    }
    //动态添加数据到Item上面

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof ItemViewHolder) {
            Log.i("info","position"+position);
            Log.i("info","process"+mProcessList.get(position).toString());
            ProcessBean process = mProcessList.get(position);

            ((ItemViewHolder) holder).mName.setText(process.getName());
            ((ItemViewHolder) holder).mMemory.setText("未确定");
            ((ItemViewHolder) holder).mType.setText("未确定");
           ((ItemViewHolder) holder).mIcon.setImageDrawable(process.getIcon());
            //测试图标
//            ((ItemViewHolder) holder).mIcon.setImageResource(R.mipmap.ic_launcher);

        }
    }
    //item的数量
    @Override
    public int getItemCount() {
        return mProcessList.size();
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder  {

        TextView mName;
        TextView mMemory;
        TextView mType;
        ImageView mIcon;

        public ItemViewHolder(View v) {
            super(v);
            mName = (TextView) v.findViewById(R.id.tv_process_name);
            mMemory = (TextView) v.findViewById(R.id.tv_process_memory);
            mIcon = (ImageView) v.findViewById(R.id.iv_process);
            mType = (TextView) v.findViewById(R.id.tv_process_type);

        }


    }

}
